<link rel="stylesheet" href="/opebs/css/bootstrap.min.css">
  <link rel="stylesheet" href="/opebs/css/bootstrap-select.css">

  <script src="/opebs/js/jquery.min.js"></script>
  <script src="/opebs/js/bootstrap.min.js"></script>
  <script src="/opebs/js/bootstrap-select.js"></script>


<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>

<table class="table table-bordered table-condensed" style="margin-left: 2px;margin-right: 2px;width: 99%">
        <tbody>
        <tr>
        <#--<#if flag=='loc1'>-->
            <td colspan="6">
                <input class="btn btn-success btn-lg radius" id="incollection" type="button" value="进厂采集">
                <input class="btn btn-success btn-lg radius disabled"  id="save"  type="button" value="保存数据">
                <input class="btn btn-success btn-lg radius disabled" id="write" type="button" value="写卡">
                <input class="btn btn-success btn-lg radius" id="reset" type="button" value="进厂重置">
                <#--<input class="btn btn-success btn-lg radius" id="clearLoc1" type="button" value="清卡">-->
            </td>
        <#--</#if>-->
           <#if flag=='loc2'>
               <td colspan="6">
                   <input class="btn btn-success btn-lg radius" id="read" type="button" value="读卡">
                   <input class="btn btn-success btn-lg radius disabled" id="outcollection" type="button" value="出厂采集">
                   <input class="btn btn-success btn-lg radius disabled"  id="outSave"  type="button" value="保存数据">
                   <input class="btn btn-success btn-lg radius disabled" id="print" type="button" value="打印">
                   <#--<input class="btn btn-success btn-lg radius" id="clear" type="button" value="清卡">-->
                   <input class="btn btn-success btn-lg radius" id="outReset" type="button" value="出厂重置">
               </td>
           </#if>
        </tr>
        <tr>
            <td width="5%" style="text-align: center;line-height:30px;height: 30px">供应商</td>
            <td width="18%">
                <select id="supplierName" name="supplierName" class="selectpicker form-control"  data-live-search="true" style="width: 100%;height: 100%">
                    <option data-tokens="">请选择</option>
                    <#if supplier??>
                        <#list supplier as m>
                             <option data-tokens="${m.value}">${m.name}</option>
                        </#list>
                    </#if>
                </select>
            </td>
            <td width="5%" style="text-align: center;line-height:30px;height: 30px">采购商</td>
            <td width="18%">
                <select id="customerName" name="customerName" class="selectpicker form-control"  data-live-search="true">
                    <option data-tokens="">请选择</option>
                    <#if customer??>
                        <#list customer as m>
                             <option data-tokens="${m.value}">${m.name}</option>
                        </#list>
                    </#if>
                </select>
            </td>
            <td width="5%" style="text-align: center;line-height:30px;height: 30px">物料</td>
            <td width="18%">
                <select id="materialName" name="materialName" class="selectpicker form-control"  data-live-search="true">
                    <option data-tokens="">请选择</option>
                    <#if materials??>
                        <#list materials as m>
                             <option data-tokens="${m.value}">${m.name}</option>
                        </#list>
                    </#if>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="3" >
                <div  style="text-align:center;background:#222222;height:140px;">
                    <span id="sec" style="color:#ff0509;line-height: 135px;font-size: 110px;">48.5</span>
                </div>
            </td>
            <td colspan="3">
            <#--<#if flag=='loc1'>-->
                <div style="text-align:center;background:#222222;height:140px;">
                    <span id="info" style="color:#ff0509;line-height: 135px;font-size: 110px;">晋A517B6</span>
                </div>
            <#--</#if>-->
            <#if flag=='loc2'>
                <div style="text-align:center;background:#222222;height:140px;">
                    <span id="outInfo" style="color:#ff0509;line-height: 135px;font-size: 110px;">待读卡</span>
                </div>
            </#if>
            </td>

        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">供应商</td>
            <td><input type="text"  class="form-control" id="supplierNameCode" readonly  name="supplierNameCode" style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">采购商</td>
            <td><input type="text" name="customerNameCode" id="customerNameCode" readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">物料</td>
            <td><input type="text" name="materialNameCode" id="materialNameCode" readonly class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">磅单号</td>
            <td><input type="text"  class="form-control" id="measureId" readonly name="measureId"  style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">车牌号</td>
            <td>
                <div class="form-inline" >
                    <select class="select" style="width: 20%;height: 33px;background-color:#F0F0F0;border: 0" id="main-plate-no-pre" name="main-plate-no-pre"></select>
                    <input type="text" name="carId-f" id="carId-f" onblur="confirmCar()" style="background-color:#F0F0F0;width:68%;height:32px;margin-left:-5px;margin-top:-5px;border:0;">
                </div>
            </td>
            <td style="text-align: center;line-height:30px;height: 30px">净重</td>
            <td><input type="text" name="suttle" id="suttle" readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">毛重</td>
            <td><input type="text" name="gross" id="gross"   readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">毛重时间</td>
            <td ><input type="text"  name="grossTime" readonly  id="grossTime" class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">毛重司磅员</td>
            <td><input type="text" name="grossWeightP" readonly id="grossWeightP" class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">皮重</td>
            <td><input type="text"  name="tare" id="tare" readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">皮重时间</td>
            <td><input type="text" name="tareTime" id="tareTime" readonly class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">皮重司磅员</td>
            <td><input type="text" name="tareP" id="tareP"readonly class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">关闭标记</td>
            <td><input type="text" name="closeSymbol" id="closeSymbol" readonly   class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">卸装标记</td>
            <td><input type="text" name="unloadSymbol" id="unloadSymbol" readonly class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">退货标记</td>
            <td><input type="text" name="returnSymbol" id="returnSymbol" readonly class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td width="9%" style="text-align: center;line-height:30px;height: 30px">退卸备注</td>
            <td width="15%"><input type="text" name="remarks1" id="remarks1" readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
            <td width="9%" style="text-align: center;line-height:30px;height: 30px">备注</td>
            <td width="15%"><input type="text" name="remark2" id="remark2"  class="form-control"style="background-color:#F0F0F0;border:0;"></td>
            <td width="9%" style="text-align: center;line-height:30px;height: 30px">最大载重量</td>
            <td width="15%"><input type="text" name="max" id="max" readonly  class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr id="source" style="display: none">
            <td style="text-align: center;line-height:30px;height: 30px">原发毛重</td>
            <td><input type="text" name="sourceGross" id="sourceGross"  class="form-control"style="background-color:#F0F0F0;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">原发皮重</td>
            <td><input type="text"  name="sourceTare" id="sourceTare"  class="form-control"style="background-color:#F0F0F0;border:0;"></td>
            <td style="text-align: center;line-height:30px;height: 30px">原发净重</td>
            <td><input type="text" name="sourceSuttle" readonly  id="sourceSuttle"  class="form-control"style="background-color:#cef0ce;border:0;"></td>
        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">卸装时间</td>
            <td>
                <input type="text" name="unloadDate" id="unloadDate" class="form-control"style="background-color:#cef0ce;border:0;" readonly>
            </td>
            <td style="text-align: center;line-height:30px;height: 30px">毛重计量点</td>
            <td>
                <input type="text" name="grossWeightSite" id="grossWeightSite" class="form-control"style="background-color:#cef0ce;border:0;" readonly>
            </td>
            <td style="text-align: center;line-height:30px;height: 30px">皮重计量点</td>
            <td>
                <input type="text" name="tareSite" id="tareSite" class="form-control"style="background-color:#cef0ce;border:0;" readonly>
            </td>


        </tr>
        <tr>
            <td style="text-align: center;line-height:30px;height: 30px">库房名称</td>
            <td>
                <input type="text" hidden name="storageName" id="storageName" class="form-control"style="background-color:#cef0ce;border:0;" readonly>
            </td>
            <td></td><td></td><td></td><td></td>
        </tr>
        </tbody>
    </table>
<!-- 读秤和车牌 -->
<script type="text/javascript">
    var position = '${desc!}';
    $(document).ready(function(){

        // measureInfo();
        // carInfo();
    });
    function measureInfo(){
        var flag = '${flag}';
        $.ajax({
            url : '/measure-info',
            data : {flag:flag,tm:new Date()},
            async:true,
            // timeout:1000,
            success :function(data){
                $('#sec').html(data.sec);
            },
            error:function (XMLHttpRequest, textStatus, errorThrown) {
            },
            complete:function(XMLHttpRequest , textStatus){
                setTimeout(measureInfo(), 1000);
            }
        })
    };
    function carInfo(){
        var flag = '${flag}';
        $.ajax({
            // url : '/car-info/' + datatime,
            url : '/car-info',
            data : {flag:flag,tm:new Date()},
            async:true,
            // timeout:5000,
            success:function(data){
                $('#info').html(data.car);
            },
            complete:function(XMLHttpRequest , textStatus){
                setTimeout(carInfo(), 5000);
            }
        })
    };
    $('#write').click(function(){
        layer.msg('写卡中', {icon: 1});
        var measureId = $('#measureId').val();
        if(measureId==''){
            layer.msg('计量单号不存在，请确认业务', {icon: 2});
            return false;
        }
        $.ajax({
            url: '/measure-write/'+measureId,
            async : false,
            success:function(data){
                layer.msg('写卡成功',{time:30*1000});
                init();
                $('#write').addClass("disabled");
                $('#incollection').removeClass("disabled");
                $('#source').hide();
            }
        })
    })
</script>
<!-- 初始化省简称 -->
<script type="text/javascript">
    var sedDomMain = $('#main-plate-no-pre');
    var provinces = new Array("京","沪","浙","苏","粤","鲁","冀",
            "豫","川","渝","辽","吉","黑","皖","鄂",
            "津","贵","云","桂","琼","青","新","藏",
            "蒙","宁","甘","陕","闽","赣","湘");

    sedDomMain.append('<option value="晋">晋</option>')
    for(var i=0;i<provinces.length;i++){
        sedDomMain.append("<option value='"+provinces[i]+"'>"+provinces[i]+"</option>");
    }
</script>

<!-- 手工输入车号确认 -->
<script type="text/javascript">
    var people = '${user.nickname}';
    function confirmCar(){
        var pre = $('#main-plate-no-pre').val();
        var carId = $('#carId-f').val();
        if(pre==-1){
            alert('请选择省份简称');
        }else{
            var car = pre + carId;
            $.ajax({
                url : '/car-check/'+car,
                async: true,
                success: function(data){
                    var url = '/car-add/'+data.car.toUpperCase();
                        var index = layer.open({
                            title:'车辆新增',
                            type: 2,
                            closeBtn:1,
                            area: ['900px', '700'],
                            fixed: false, //不固定
                            maxmin: false,
                            content: url
                        });
                }
            })
        }
    }
</script>

<!-- 引入读卡js -->
<script type="text/javascript" src="/operation/read.js"></script>

<!-- 引入保存js -->
<script type="text/javascript" src="/operation/save.js"></script>

<!-- 引入保存js -->
<script type="text/javascript" src="/operation/outSave.js"></script>

<!-- 引入进厂采集js -->
<script type="text/javascript" src="/operation/incollection.js"></script>

<!-- 引入出厂采集js -->
<script type="text/javascript" src="/operation/outcollection.js"></script>

<!-- 引入打印js -->
<script type="text/javascript" src="/operation/print.js"></script>

<!-- 引入清卡js -->
<script type="text/javascript" src="/operation/clear.js"></script>

<!-- 引入出厂重置js -->
<script type="text/javascript" src="/operation/outReset.js"></script>

<!-- 引入进厂重置js -->
<script type="text/javascript" src="/operation/reset.js"></script>

<!-- 引入写卡重置js -->
<#--<script type="text/javascript" src="/operation/write.js"></script>-->

<script type="text/javascript">

    var reg = new RegExp("^[0-9]+(.[0-9]{1,3})?$");

    $('#sourceGross').change(function () {
        var gross = $('#sourceGross').val();
        if(gross!=''&&reg.test(gross)){
            var tare = $('#sourceTare').val();
            if(tare!=''&&reg.test(tare)){
                var suttle = parseFloat(gross) - parseFloat(tare);
                $('#sourceSuttle').val(suttle);
            }
        }else if(gross!=''&&!reg.test(gross)){
            layer.msg('只能输入数字');
            $('#sourceGross').val('');
            $('#sourceSuttle').val('');
        }
    });
    $('#sourceTare').change(function () {
        var tare = $('#sourceTare').val();
        if(tare!=''&&reg.test(tare)){
            var gross = $('#sourceGross').val();
            if(gross!=''&&reg.test(gross)){
                var suttle = parseFloat(gross) - parseFloat(tare);
                $('#sourceSuttle').val(suttle);
            }
        }else if(tare!=''&&!reg.test(tare)){
            layer.msg('只能输入数字');
            $('#sourceTare').val('');
            $('#sourceSuttle').val('');
        }
    });
</script>

<script type="text/javascript">

    $('#supplierName').change(function () {
        var supplierCode = $('#supplierName').val()
        $('#supplierNameCode').val(supplierCode);
    });
    $('#customerName').change(function () {
        var customerCode = $('#customerName').val()
        $('#customerNameCode').val(customerCode);
    });
    $('#materialName').change(function () {
        var materialCode = $('#materialName').val()
        $('#materialNameCode').val(materialCode);
    });

</script>
<script type="text/javascript">
    function getLocalTime() {
        var myDate = new Date();
        var year=myDate.getFullYear();
        var month=myDate.getMonth()+1;
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
        var now=year+'-'+getNow(month)+"-"+getNow(date)+" "+getNow(h)+':'+getNow(m)+":"+getNow(s);
        return now;
    }
    function getNow(s) {
        return s < 10 ? '0' + s: ''+s;
    }
    function getMeasureId(){
        var myDate = new Date();
        var year=myDate.getFullYear();
        var month=myDate.getMonth()+1;
        var date=myDate.getDate();
        var h=myDate.getHours();       //获取当前小时数(0-23)
        var m=myDate.getMinutes();     //获取当前分钟数(0-59)
        var s=myDate.getSeconds();
        var now=year+getNow(month)+getNow(date)+getNow(h)+getNow(m)+getNow(s);
        return now;
    }
    function init(){
        // $('#customerNameCode').val('');
        // $('#supplierNameCode').val('');
        // $('#materialNameCode').val('');
        $('#measureId').val('');
        $('#gross').val('');
        $('#grossTime').val('');
        $('#tare').val('');
        $('#tareTime').val('');
        $('#suttle').val('');
        $('#grossWeightP').val('');
        $('#unloadSymbol').val('');
        $('#closeSymbol').val('');
        $('#returnSymbol').val('');
        $('#remarks1').val('');
        $('#supplierName').val('');
        $('#customerName').val('');
        $('#carId-f').val('');
        $('#materialName').val('');
        $('#sourceGross').val('');
        $('#sourceTare').val('');
        $('#sourceSuttle').val('');
        $('#remark2').val('');
        $('#tareP').val('');
        $('#max').val('');
        $('#unloadDate').val('');
        $('#grossWeightSite').val('');
        $('#tareSite').val('');
        $('#storageName').val('');
    }
</script>
